/* 
 *	Copyright (C) 2009-2010 miaohua
 *	http://code.google.com/p/lrcshower/
 *
 *  This Program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *   
 *  This Program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with GNU Make; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
 *  http://www.gnu.org/copyleft/gpl.html
 *
 */

#pragma once
#include <utility>
#include "TypeDef.h"
#include "SearchEngineComHdr.h"

enum LocalFolderType{LrcFolder, SongFolder, UserFolder};
extern const TCHAR * LocalFolder[UserFolder+1];

typedef std::vector<std::pair<tstring, tstring> > FolderList;

// Search engine api
typedef const TCHAR* (__stdcall*pGetEngineName)();
typedef int (__stdcall*pSearchSong)(const tstring & SongName, tstring & ErrMsg, SongList & List, int Page);
typedef int (__stdcall*pSearchLrc)(const tstring & Song, const tstring & Singer, tstring & ErrMsg, LrcList & List, int Page);
typedef bool (__stdcall*pGetMp3DownloadUrl)(int Idx, tstring & Url);
typedef bool (__stdcall*pGetLrcDownloadUrl)(int Idx, tstring & Url);
typedef int (__stdcall*pGetSongTotalNum)();
typedef int (__stdcall*pGetLrcTotalNum)();
typedef bool (__stdcall*pGetEngineLogo)(HBITMAP & Logo);

struct EngineAPI
{
   pGetEngineName GetEngineName;
   pSearchSong    SearchSong;
   pSearchLrc     SearchLrc;
   pGetMp3DownloadUrl GetMp3DownloadUrl;
   pGetLrcDownloadUrl GetLrcDownloadUrl;
   pGetSongTotalNum   GetSongTotalNum;
   pGetLrcTotalNum    GetLrcTotalNum;
   pGetEngineLogo     GetEngineLogo;
};

typedef std::vector<EngineAPI>  SearchEngineAPI;

// Struct LrcSearchSetting is used to hold parameters for lrc online search functions
// It has functions to serialize and deserialize to XML & window's reg
struct LrcSearchSetting
{
      LrcSearchSetting(const tstring & RegPath);
	  ~LrcSearchSetting();

      bool SerializeToReg();
	  bool DeserializeFromReg();

	  bool SerializeToXML();
	  bool DeserializeFromXML();

	  void SetDefaultVal();

      bool CheckDefaulFolder(int Index);
      bool GetLrcDownloadUrl(unsigned int LrcIdx, tstring & LrcUrl);

      //tstring m_Singer;                 // Singer name
      //tstring m_Song;                   // Song name
      LrcList m_LrcList;                // Lrc files' list
      FolderList m_FolderList;          // Folders for local search
      tstring m_FolderPath;             // Folder Path for saving downloaded lrc files
      int m_SearchEngineIdx;            // Index of search engine
      SearchEngineAPI m_SearchEngineAPI;// Search engine apis
      bool m_AutoSearch;                // Auto search when playing
      bool m_SelRandom;                 // Randomly select one lrc file when there are more
      bool m_PromptMulti;               // Prompt to user when there are more lrc files
      bool m_AutoParse;                 // Auto parse media file to get song and singer information 
      tstring m_RegPath;                // Parameters save & load windows register path
};